﻿
using LxCFD;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;

namespace TimeSolve
{
    public class SolverWindowViewModel : BindableBase
    {
        public SolverWindowViewModel()
        {
            mainVM = MainViewModel.mainViewModel;
            dcdel = new DelegateCommand(_dcdel);
            dccopy = new DelegateCommand(_dccopy);
            dcnew = new DelegateCommand(_dcnew);
            import = new DelegateCommand(_import);
            export = new DelegateCommand(_export);

            copyMaterial = new DelegateCommand(_copyMaterial);
            test = new DelegateCommand(_test);
        }
        public MainViewModel mainVM { get => _mainVM; set { _mainVM = value; RaisePropertyChanged("mainVM"); } }
        private MainViewModel _mainVM;
        public ContinuumVM selectedContinuum
        {
            get => _selectedContinuum;
            set
            {
                _selectedContinuum = value;
                RaisePropertyChanged("selectedContinuum");
            }
        }
        private ContinuumVM _selectedContinuum;

        #region command
        public DelegateCommand dcdel { get; set; }
        public DelegateCommand dccopy { get; set; }
        public DelegateCommand dcnew { get; set; }
        public DelegateCommand import { get; set; }
        public DelegateCommand export { get; set; }
        public DelegateCommand copyMaterial { get; set; }


        private void _dcnew()
        {
            for (int i = mainVM.continuums.Count + 1; i < 10000; i++)
            {
                string newname = string.Format("物理模型 {0}", i);
                //newname = namehead + i;
                if (_isValidName(newname))
                {
                    PhysicalModel physical = new PhysicalModel() { name = newname };
                    ContinuumVM pm = new ContinuumVM(physical);
                    mainVM.continuums.Add(pm);
                    return;
                }
            }
            LxConsole.Error("创建物理模型失败，无可用名称");
        }

        private void _dcdel()
        {

        }
        private void _dccopy()
        {

        }
        private void _import()
        {

        }
        private void _export()
        {

        }
        private bool _isValidName(string s)
        {
            foreach (var g in mainVM.continuums)
            {
                if (s == g.name)
                {
                    return false;
                }
            }
            return true;
        }

        private void _copyMaterial()
        {

        }
        #endregion
        public DelegateCommand test { get; set; }
        public void _test()
        {
            //string namehead = "测试模型 ";
            //string newname = "";
            //for (int i = 1; i < 10000; i++)
            //{
            //    newname = namehead + i;
            //    if (_isValidName(newname))
            //    {
            //        ContinuumVM pm = new ContinuumVM() { name = newname };
            //        mainVM.continuums.Add(pm);
            //        return;
            //    }
            //}
        }
    }
}

